package com.smile.config.entity;

import com.smile.config.entity.base.SuperBaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.elasticsearch.annotations.Document;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * http://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#envers
 */
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "entityCache")
@Cacheable(true)
@Entity(name = "User")
@Table(name = "User")
@AllArgsConstructor
@NoArgsConstructor
@DynamicUpdate
@DynamicInsert
@Data
@Document(indexName="smile", type="userName", shards=5,replicas=1,indexStoreType="fs",refreshInterval="-1")
//@Audited
public class User extends SuperBaseEntity implements Serializable {
    private static final long serialVersionUID = 6747315683723036484L;

    @Column(nullable = false, unique = true)
    private String userName;

    @Column(nullable = false)
    private String passWord;

    @Column(nullable = false, unique = true)
    private String email;

    @Column(nullable = true, unique = true)
    private String nickName;

    @Column(nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date regTime;

    public User buildUser() {
      return new User();
    }

}
